import inputCommon from '../../../../mixin/inputCommon'
import QRCode from 'qrcode'

export default {
  name: 'render',
  props: ['config', 'editor', 'readonlyMain', 'isMobile'],
  inject: ['rootForm'],
  mixins: [inputCommon],
  data() {
    return {
      valEmpty: true
    }
  },
  mounted() {
    this.$watch(this.getParsedEx('contentExpression'), (v) => {
      if (v) {
        this.valEmpty = true
        this.$nextTick(() => {
          this.$el.classList && this.$el.classList.add(this.pluginUniqueId)
          QRCode.toCanvas(document.querySelector(`.${this.pluginUniqueId} .canvas`), v, function (error) {
            if (error) console.error(error)
          })
        })
      } else {
        this.valEmpty = false
      }
    }, { immediate: true })
  }
}
